<template>
	<view>
		<u-cell-group>
			<u-cell-item title="申请时间" :arrow="false">
				<u-input :value="apply_time" placeholder="" @click="showApplyTimePicker = true" :selectOpen="showApplyTimePicker" type="select" inputAlign="right"></u-input>
			</u-cell-item>
			<u-cell-item :border-bottom="false" title="申请备注" :arrow="false">
				<u-input v-model="form.Remark" type="textarea" inputAlign="right" placeholder="申请备注"></u-input>
			</u-cell-item>
		</u-cell-group>
		
		<u-picker :default-time="form.ApplyTime ? $u.date(form.ApplyTime, 'yyyy-mm-dd') : $u.date(new Date())" @confirm="onApplyTimeChange" v-model="showApplyTimePicker" mode="time" :params="{year: true, month: true, day: true}"></u-picker>
	</view>
</template>

<script>
	export default {
		name:"apply-form",
		data() {
			return {
				showApplyTimePicker: false,
				
				form: {
					ApplyTime: parseInt(new Date().getTime() / 1000),
					Remark: ''
				}
			};
		},
		
		methods: {
			onApplyTimeChange(e) {
				this.form.ApplyTime = parseInt(new Date(`${e.year}-${e.month}-${e.day}`).getTime() / 1000)
			},
			
			initForm(data) {
				if(data.ApplyTime) {
					this.form.ApplyTime = data.ApplyTime
				}
				if(data.Remark) {
					this.form.Remark = data.Remark;
				}
			}
		},
		
		computed: {
			apply_time() {
				if(this.form.ApplyTime) {
					return this.$u.date(this.form.ApplyTime)
				}else {
					return ''
				}
			}
		}
	}
</script>

<style lang="scss">

</style>
